package com.lynx.system.service;

import com.lynx.system.beans.Menu;
import com.lynx.system.beans.Type;
import com.lynx.system.repository.MenuRepository;
import com.lynx.system.repository.TypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class MenuServiceImpl implements MenuService {
    @Autowired
    private MenuRepository menuRepository;
    @Autowired
    private TypeRepository typeRepository;
    @Override
    public List<Menu> findAll(int index, int limit) {
        return menuRepository.selectAll((index-1)*limit,limit);
    }

    @Override
    public int findCount() {
        return menuRepository.selectCount();
    }

    @Override
    public void deleteById(int id) {
        menuRepository.deleteMenu(id);
    }

    @Override
    public List<Type> getTypes() {
        return typeRepository.selectAll();
    }

    @Override
    public int save(Menu menu) {
        menuRepository.insertMenu(menu);
        return 1;
    }

    @Override
    public Menu findById(int id) {
        return menuRepository.selectById(id);
    }

    @Override
    public int edit(Menu menu) {
        menuRepository.updateMenu(menu);
        return 1;
    }
}
